All right.
So I'm in my battle Royale arena area, and I wanted to take a quick look at my battle manager, point
some things out.
So if you forgot what a battle manager is.
Server script service.
Battle manager.
All right.
So what happens when we get teleported to our world, to our arena?
The server will be provisioned, the players will enter the game, and then this script is read.
We go down here and at the bottom, boom, we fire off the battle.
We get to here, wait three seconds, and then we have our countdown.
Beep, beep, beep, beep, beep.
If other people are joining the game, that's fine.
They're in the battle, too.
So we're going to do here is I'm going to set some flags and then I'm going to start and stop the battle
based on whether there's players present or if everybody leaves that way.
We're not relying on the server to shut down, to start up and shut down our game.
Let's just go ahead and do a local high's began.
I'm going to make that false, right?
The battle has not began, but when we call battle, it has.
We'll say highs began equals true.
All right.
So the battle started.
We're getting our countdown.
Beep, beep, beep, beep.
Let's go down here.
Now, this while loop is going to run until is ended is set.
True, there's a winner, but it's possible to not have a winner because we have one second delay in
here.
Maybe everybody left within that.
Second, there might have been two people left.
Boom.
They're both gone at the same time.
So it's fine.
The server will shut down, the loop will stop.
But let's just go ahead and turn it off.
Let's get down to here.
All right.
We can do it above our print statement.
Let me scroll a little bit so it's closer to the center.
I'm going to say if num, which is the number of players, is less than or equal to one, then let's
go ahead and make sure the battle is ended.
Is ended.
Is true.
And then we'll say has begun is false.
All right.
Now here in add player to game, this is going to fire every time someone joins the game.
And if we teleport ten people over even at the same time which is what we're doing, this is still going
to fire at different times.
People are going to show up at different times depending on your network, depending on a lot of things.
So I want to start the battle here because I want to start the battle when there's people in the world,
I just want to make sure and start at once.
So I'm going to say, if not has begun, then we'll do our battle.
But I think I'm going to spawn it so I don't tie up the thread in battle.
You don't have to spawn it.
You could just do the battle here.
But I decided to do that.
All right, Now we can get rid of this.
We don't need this now.
We don't have to worry about our start up and stopping of the server to control the start and stop of
the battle.
Although the other way will work fine.
So you're welcome to use either one.
But if you're curious, this is how you do it with code rather than the server.